function soapWrapFunc(bdStr){
    // 封装SOAP头尾
    var soapHead = '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://Webservice.zjusc.edu.cn/"><env:Body>', soapTail = '</env:Body></env:Envelope>';
    return soapHead + bdStr + soapTail;
}

$(function(){
    /*
     *
     */
});
/*
 *
 *
 */
$(window).load(function(){
    $('#forgotten a').click(function(){
        $('#retrieveWnd').show();
        $('#loginWnd').hide();
    });
    $('#backToLogin').click(function(){
        $('#retrieveWnd').hide();
        $('#loginWnd').show();
    });
    $('#txtPassword').keypress(function(e){
        if (e.keyCode == 13) {
            $('#btnLogin').trigger('click');
        }
    });
    /*登录*/
    $('#btnLogin').click(function(){
        var username = $.trim($('#txtUsername').val()), password = $.trim($('#txtPassword').val());
        if (username == '') {
            alert('用户名不能为空');
            return false;
        }
        if (password == '') {
            alert('请填写好密码');
            return false;
        }
        Tr0j4n.Cookie.Set('userName', username);
        var str = '<web:IdentifyMySelf><uname>' + username + '</uname><pwd>' + password + '</pwd></web:IdentifyMySelf>';
        $.ajax({
            type: "POST",
            contentType: "text/xml",
            url: 'Service/IdentifyService',
            data: soapWrapFunc(str),
            dataType: 'xml',
            success: function(xml){
                var uType = $(xml).find('userType').text(), aCode = $(xml).find('authCode').text();
                if (aCode != '') {
                    Tr0j4n.Cookie.Set('userCode', aCode);
                    Tr0j4n.Cookie.Set('userType', uType);
                }
                if (uType == '1') {
					 Tr0j4n.Cookie.Set('stuApplyID', $(xml).find('stuApplyID').text());
                    window.location.href = 'student.html';
                }
                else 
                    if (uType == '100') {
                        window.location.href = 'manager.html';
                    }
                    else {
                        alert('身份验证错误，请检查用户名和密码');
                    }
            },
            beforeSend: function(xhr){
                xhr.setRequestHeader("SOAPAction", "\"\"");
            },
            error: function(x, e){
                alert('error:' + x.responseText);
            },
            complete: function(x){
            
            }
        });
    });
});
